<template>
	<view class="content">
		<view><uv-action-sheet ref="actionSheet" :actions="subjectList" title="选择科目" @select="select" @close="close"></uv-action-sheet></view>
		<view class="list" v-for="item in goexaminationList">
			<view class="list-left">
				<view class="title">{{ item.testPaperName }}</view>
				<view class="name">
					<view class="">
						试题数量
						<text>{{item.num}}</text>
					</view>
					<view class="">
						考试时长
						<text>{{item.testMinute}}分钟</text>
					</view>
				</view>
			</view>
			<view class="list-right">
				<view class="start" @click="goexamination(item)">开始考试</view>
				
			</view>
		</view>
	</view>
</template>

<script>
import {
	searchPlugsPracticeTestPaperList,
	getCommonPayInfoByDataId,
	insertPlugsPracticeStudentTestRecord,
	getPracticeStudentTestCount,
	searchPlugsPracticeStudentById,insertPlugsPracticeTestRecord
} from '../../utils/api.js';
export default {
	data() {
		return {
			goexaminationList: [],
			dataId: '',
			changeName: '',
			info: {},
			subjectList: []
		};
	},
	onLoad(option) {
		this.info = JSON.parse(decodeURIComponent(option.info));
		this.changeName = this.info.subjectName;
		this.dataId = this.info.id;
		getPracticeStudentTestCount({ subjectId: this.dataId }).then(res => {});
	},
	onShow() {
		this.getbankList();
	},
	methods: {
		open() {
			this.$refs.actionSheet.open();
		},
		select(e) {
			console.log(e.subjectName);
			this.changeName = e.subjectName;
			console.log(this.changeName);
			this.dataId = e.id;
			this.getbankList();
		},
		close() {
		},

		getsubjectlist() {
			let data = {
				id: uni.getStorageSync('studentInfo').id
			};
			searchPlugsPracticeStudentById(data).then(ress => {
				this.subjectList = ress.body.practiceSubjectList;
				this.subjectList.forEach(item => {
					item.name = item.subjectName;
				});
			});
		},
		getbankList() {
			let data = {
				size: 50,
				page: 1,
				dataId: this.dataId,
				userServiceToken: 'TUW8JF4WE6D52SDL5UMN5'
			};
			searchPlugsPracticeTestPaperList(data).then(res => {
				if (res.code == 200) {
					this.goexaminationList = res.body.list;
					this.goexaminationList.forEach(item=>{
						item.num=JSON.parse(item.questionsJson).length
					})
				}
			});
		},
		goexamination(item) {
			let that = this;

			let cont = '开放考试:选择答案后，立即出结果，不进行错题统计！<br>闭卷考试：模拟真实考试环境，需要交卷统计错题!';
			let content = cont.replace(/<br>/g, '\n');
			uni.showModal({
				title: '选择考试模式',
				content: content,

				cancelText: '开放考试',
				cancelColor: '#999',
				confirmText: '闭卷考试',
				success: resp => {
					console.log(resp);
					if (resp.confirm) {

						uni.navigateTo({
							url: `/pages/paperlist/details?info=${encodeURIComponent(JSON.stringify(item))}&typeId=1&practiceId=0`
						});
					} else if (resp.cancel) {
						uni.navigateTo({
							url: `/pages/paperlist/details?info=${encodeURIComponent(JSON.stringify(item))}&typeId=0&practiceId=0`
						});
					}
				},
				fail: () => {}
			});
		}
	}
};
</script>

<style lang="scss">
uni-modal .uni-modal__bd {
	white-space: pre-wrap;
}
page {
	padding: 20rpx;
	box-sizing: border-box;
}
.top {
	display: flex;
	align-items: center;
	background-color: #f5f5f5;
	padding: 20rpx;
	margin-bottom: 20rpx;
	.top-name {
		color: $uni-text-color;
		font-size: 26rpx;
	}
	.top-icon {
	}
}
.content {
	.list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx;
		border-bottom: 1rpx solid #f5f5f5;
		.list-left {
			.title {
				color: $uni-text-color;
				font-weight: 700;
				font-size: 28rpx;
			}
			.name {
				width: 450rpx;
				display: flex;
				align-items: center;
				padding: 10rpx 0;
				justify-content: space-between;
				font-size: 24rpx;
				color: #666;
				text {
					margin-left: 10rpx;
				}
			}
		}
		.list-right {
			.start {
				font-size: 26rpx;
				color: #fff;
				background-color: royalblue;
				width: 140rpx;
				height: 50rpx;
				line-height: 50rpx;
				text-align: center;
				border-radius: 25rpx 25rpx 0 25rpx;
			}
		}
	}
}
</style>
